package com.selfdriving.adapter;

import java.util.List;
import com.selfdriving.R;
import com.selfdriving.bean.Comment;
import com.selfdriving.bean.Diary;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DiaryAdapter extends BaseAdapter {
	private Context context;

	private List<Diary> diaries;

	private HolderView holderView;

	public DiaryAdapter(Context context, List<Diary> diaries) {
		this.context = context;
		this.diaries = diaries;
	}

	@Override
	public int getCount() {
		return diaries.size();
	}

	@Override
	public Object getItem(int position) {
		return diaries.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Diary diary = diaries.get(position);
		if (convertView == null) {
			holderView = new HolderView();
			convertView = ((LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
					.inflate(R.layout.diaryl_item, null);
			convertView.setTag(holderView);
		} else {
			holderView = (HolderView) convertView.getTag();
		}
		holderView.icon = (ImageView) convertView.findViewById(R.id.ivIcon);
		holderView.explains = (TextView) convertView
				.findViewById(R.id.tvContent);
		return convertView;
	}

	private class HolderView {
		private ImageView icon;

		private TextView explains;
	}

}
